Skip to content

fix: hard-error on unknown 'auth' subcommands#245

Merged
ecv merged 2 commits into
mainfrom
fix/auth-unknown-subcommand-hard-error
Jul 13, 2026
Merged

fix: hard-error on unknown 'auth' subcommands#245
ecv merged 2 commits into
mainfrom
fix/auth-unknown-subcommand-hard-error

Conversation

@ecv

@ecv ecv commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Second half of #243. Stacked on #244 — base is fix/auth-help-stale-login-examples; review/merge #244 first, then this retargets to main.

Problem

datumctl auth login and datumctl auth logout don't error. Cobra treats the unknown subcommand as a positional arg, the auth group has no RunE, so it reprints the group help and exits 0. A user following old docs or muscle memory gets no signal the command is invalid — and (before #244) the help they saw repeated the wrong spelling.

Login/logout were deliberately promoted to top-level commands in the context-discovery redesign (#149, PR #149); they are not coming back under auth. So the fix is to fail loudly and redirect, not to re-add aliases.

Change

auth now validates its args (cobra.ArbitraryArgs + RunE):

  • Moved commands (login, logout) → targeted error with a hint at the replacement:
    $ datumctl auth login
    error: 'datumctl auth login' is now 'datumctl login'
    Log in and log out are top-level commands — run 'datumctl login'.
    $ echo $?
    1
    
  • Any other unknown subcommand → generic error pointing at --help:
    $ datumctl auth bogus
    error: unknown command "bogus" for 'datumctl auth'
    Run 'datumctl auth --help' for available commands.
    
  • Bare datumctl auth → still prints help, exits 0.
  • Valid subcommands (list, switch, get-token, update-kubeconfig) route unchanged.

Both errors carry a machine-readable Code (AUTH_COMMAND_MOVED, UNKNOWN_SUBCOMMAND) so structured (--error-format json) consumers and agents can branch on them:

$ datumctl auth logout --error-format json
{"error":{"code":"AUTH_COMMAND_MOVED","message":"'datumctl auth logout' is now 'datumctl logout'","hint":"...","retryable":false}}

Tests

internal/cmd/auth/auth_test.go covers bare-auth-help, both moved-command hints, the generic unknown case, and that valid subcommands still resolve. go build ./... and go test ./internal/cmd/auth/... pass.

Running 'datumctl auth login' or 'datumctl auth logout' silently
reprinted the auth group help and exited 0, giving users no signal the
command was invalid. Login and logout moved to the top level in the
context-discovery redesign (#149), but older docs and muscle memory
still reach for the auth-scoped spelling.

The auth command now validates its args: an unrecognized subcommand
returns a UserError (exit 1) instead of a success. Names that were
promoted to the top level get a targeted hint pointing at the
replacement command; other unknown names get a generic error directing
users to --help. Both carry a machine-readable Code (AUTH_COMMAND_MOVED,
UNKNOWN_SUBCOMMAND) for structured error consumers.

Bare 'datumctl auth' still prints help and exits 0; valid subcommands
route unchanged.

Refs #243
@ecv ecv force-pushed the fix/auth-unknown-subcommand-hard-error branch from 915b54f to 57a0be6 Compare July 12, 2026 18:33
Base automatically changed from fix/auth-help-stale-login-examples to main July 12, 2026 18:35
@ecv ecv requested a review from scotwells July 12, 2026 18:36
@ecv ecv enabled auto-merge July 13, 2026 18:07
@ecv ecv requested a review from scotwells July 13, 2026 18:12
@ecv ecv merged commit 5701730 into main Jul 13, 2026
3 checks passed
@ecv ecv deleted the fix/auth-unknown-subcommand-hard-error branch July 13, 2026 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants